const BASEURL = 'http://localhost:3000/api/'

const request = ({
  url,
  method = 'GET',
  data = {},
  header = {},
  tip = '拼命加载中。。。'
}) => {
  return new Promise((resolve, reject) => {
    const token = wx.getStorageSync('token')
    if(token){
      header.Authorization = token
    }
    wx.showLoading({
      title: tip,
    })
    wx.request({
      url: `${BASEURL}${url}`,
      method,
      data,
      header,
      success: res => {
        // console.log('成功')
        resolve(res.data)
      },
      fail: err => {
        reject(err)
      },
      complete: () => {
        wx.hideLoading()
      }
    })
  })
}
wx.$request = request
export default request